<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
	<head>
		<script src="js/jquery.js"></script>
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="format-detection" content="telephone=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style">
		<link href="css/bksystem.css" rel="stylesheet" type="text/css" /> 
		<link href="font/iconfont.css" rel="stylesheet" type="text/css" />
		<link href="css/module.css" rel="stylesheet" type="text/css" />
		<link href="css/pages.css" rel="stylesheet" type="text/css" />
		<title>管理员信息</title>
		<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
		<script src="js/jquery.cookie.js" type="text/javascript"></script>
		<script src="js/jquery.nicescroll.js" type="text/javascript"></script>
		<script src="js/HUpages.js" type="text/javascript"></script>
		<style>
			body {
				font-family: Arial, sans-serif;
				background-color: #F5F5F5;
				margin: 0;
				padding: 20px;
			}

			h1 {
				font-weight: bold;
				color: #333;
				margin-bottom: 30px;
			}

			form {
				margin-bottom: 20px;
			}

			label {
				display: inline-block;
				width: 120px;
				text-align: right;
				margin-right: 10px;
				font-weight: bold;
			}
			input[type="text"],
			select {
				padding: 5px;
				border: 1px solid #999;
				border-radius: 3px;
			}

			input[type="submit"],
			input[type="button"] {
				padding: 8px 16px;
				font-weight: bold;
				background-color: #007bff;
				color: #FFF;
				border: none;
				border-radius: 3px;
				cursor: pointer;
			}

			table {
				width: 100%;
				border-collapse: collapse;
			}

			th, td {
				padding: 8px;
				border-bottom: 1px solid #DDD;
				text-align: center;
			}

			th {
				background-color: #f2f2f2;
				font-weight: bold;
			}

			tr:nth-child(even) {
				background-color: #f9f9f9;
			}

			.error-message {
				color: red;
				font-weight: bold;
				margin-top: 10px;
			}
		</style>
	</head>

	<body>
	<h1>管理员信息</h1>

		<label for="name">管理员姓名：</label>
		<input type="text" name="name" id="name">
		<input type="submit" value="搜索" onclick="likeAdmin()">

	<form action="" method="post">
		<div style="text-align: right;">
			<input type="button" value="新增管理员"onclick="window.location.href='add.jsp';">
		</div>
		<table>
			<thead>
			<tr>
				<th>管理员姓名</th>
				<th>账号</th>
				<th>密码</th>
				<th>手机号</th>
				<th>邮箱号</th>
				<th>账号余额</th>
				<th>是否认证</th>
				<th>操作1</th>
				<th>操作2</th>
			</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
		<script>
			$.ajax({
				"url": "AdminServlet",
				"type": "post",
				"dataType": "json",
				"success": function(data) {
					var tbodyStr = "";
					$(data).each(function(index, item) {
						tbodyStr += '  <tr>' +
								'        <td>'+ item.adminName + '</td>'+
								'        <td>'+ item.account+ '</td>'+
								'        <td>'+ item.cipher+ '</td>'+
								'        <td>'+ item.telephone + '</td>'+
								'        <td>'+ item.email+ '</td>' +
								'        <td>￥'+ item.balance+ '</td>' ;
						if (item.authentication === 1) {
							tbodyStr += '<td style="color: green">已认证</td>';
						} else if (item.authentication === 0) {
							tbodyStr += '<td style="color: red">未认证</td>';
						}
						if (item.authentication===1){
							tbodyStr+='       <td><a onclick="update()" style="text-decoration: underline; color: red;">禁用</a></td>' ;
						}else if (item.authentication===0){
							tbodyStr+='       <td><a onclick="update()" style="text-decoration: underline; color: green;">启用</a></td>' ;
						}
						tbodyStr +=
								'        <td><a onclick="del(\'' + item.id + '\')" style="text-decoration: underline; color: red;">删除</a></td>' +' ' +
								'      </tr>';
					});
					$("tbody").html(tbodyStr);
				}
			});//管理员列表
			function likeAdmin() {
				var name = $("#name").val();
				$.ajax({
					"url": "AdminLikeServlet",
					"type": "post",
					data: {"name": name},
					"dataType": "json",
					"success": function(data) {
						var tbodyStr = "";
						$(data).each(function(index, item) {
							tbodyStr += '  <tr>' +
									'        <td>'+ item.adminName + '</td>'+
									'        <td>'+ item.account+ '</td>'+
									'        <td>'+ item.cipher+ '</td>'+
									'        <td>'+ item.telephone + '</td>'+
									'        <td>'+ item.email+ '</td>' ;
							if (item.authentication === 1) {
								tbodyStr += '<td style="color: green">已认证</td>';
							} else if (item.authentication === 0) {
								tbodyStr += '<td style="color: red">未认证</td>';
							}
							if (item.authentication===1){
								tbodyStr+='       <td><a onclick="updateTop(\'' + item.id + '\')" style="text-decoration: underline; color: #ff0000;">禁用</a></td>' ;
							}else if (item.authentication===0){
								tbodyStr+='       <td><a onclick="update(\'' + item.id + '\')" style="text-decoration: underline; color: green;">启用</a></td>' ;
							}
							tbodyStr +=
									'        <td><a onclick="del(\'' + item.id+'\')" style="text-decoration: underline; color: red;">删除</a></td>' +' ' +
									'      </tr>';
						});
						$("tbody").html(tbodyStr);
					}
				})
			}//模糊查询
			function del(idStr) {
			var result = confirm("确认删除这位管理员?");
			if (result) {
				$.ajax({
					url: "AdminDelServlet",
					type: "post",
					data: "id=" + idStr,
					success: function (temp) {
						if (parseInt(temp) > 0) {
							alert("删除成功");
							location.reload();
						} else {
							alert("删除失败!");
						}
					}
				})
			}
			}//删除管理员
			function update(idStr) {
				var result = confirm("确认禁用这位管理员吗?");
				if (result) {
					$.ajax({
						url: "AdminUpServlet",
						type: "post",
						data: "id=" + idStr,
						success: function (temp) {
							if (parseInt(temp) > 0) {
								alert("禁用成功");
								location.reload();
							} else {
								alert("禁用失败!");
							}
						}
					})
				}
			}
			function updateTop() {
				var result = confirm("确认启用这位管理员吗?");
				if (result) {
					$.ajax({
						url: "AdminUpTopServlet",
						type: "post",
						data: "id=" + idStr,
						success: function (temp) {
							if (parseInt(temp) > 0) {
								alert("启用成功");
								location.reload();
							} else {
								alert("启用失败!");
							}
						}
					})
				}
			}
		</script>
	</form>
	</body>
</html>